1 using UnityEngine;
2 using
System.Collections;
3
4 namespace
GamePlay
5 {
6     
public class Combo : MonoBehaviour
7     {
8         
private BitmapFont fontCombo;
9         
public GameObject label;
10         
public GameObject task;
11         
public GameScreen gameScreen;
12
13         
private float stateTime;
14         
private bool isVisibled;
15
16         
private bool isRunning;
17
18         
private float totalTime;
19
20         
private int numberCombo;
21
22         
private ComboType comboType;
23
24         
private string[] texts;
25         
private int comboIndex;
26
27         
private bool isUpdateTask;
28
29         
private Vector3 pl;
30
31         
public void Start()
32         {
33             isRunning =
true;
34             totalTime =
5;
35             texts =
new string[] { "a", "s", "d", "f", "g", "h", "j", "k", "" };
36             
this.comboIndex = -1;
37             
this.comboType = ComboType.NONE;
38             
this.pl = label.transform.localPosition;
39             gameObject.SetActive(
false);
40         }
41
42         
public void setFont(BitmapFont comboFont)
43         {
44             fontCombo =
new BitmapFont(comboFont, label);
45         }
46          
47         
public void setCombo(int comboIndex)
48         {
49             
if (comboIndex == -1)
50             {
51                 SetVisible(
false);
52                 numberCombo =
0;
53                 
return;
54             }
55             
if (this.comboIndex != comboIndex)
56             {
57                 
this.comboIndex = comboIndex;
58                 numberCombo =
1;
59                 SetVisible(
false);
60             }
61             
else
62             {
63                 numberCombo++;
64                 
if (numberCombo >= 2)
65                 {
66                     SetVisible(
true);
67                     isUpdateTask =
true;
68                     stateTime = totalTime;
69                 }
70             }
71         }
72
73         
public int getNumberCombo()
74         {
75             
return this.numberCombo;
76         }
77
78         
private void SetVisible(bool isVisibled)
79         {
80             
this.isVisibled = isVisibled;
81             
if (isVisibled)
82             {
83                 gameObject.SetActive(
true);
84                 stateTime = totalTime;
85                 task.transform.localScale =
new Vector3(1, 1, task.transform.localScale.z);
86                 fontCombo.setText(texts[comboIndex] +
"x" + numberCombo + " COMBO", -2, 18, "GUI", "GUI");
87                 
/*
88                 label.GetComponent<Actor>().addAction(
new ActionRepeat(4, new ActionSequence(
89                     
new ActionMoveTo(pl.x, pl.y + 0.1f, 0.2f, Interpolation.sine),
90                     
new ActionMoveTo(pl.x, pl.y, 0.2f, Interpolation.sine))));
91                  * */

92             }
93             
else
94             {
95                 
if (label.GetComponent<Actor>() != null)
96                 {
97                     Actor[] acts = label.GetComponents<Actor>();
98                     
for (int i = 0; i < acts.Length; i++)
99                         Destroy(acts[i]);
100                 }
101                 
//numberCombo = 0;
102                 gameObject.SetActive(
false);
103             }
104         }
105
106         
public void Update()
107         {
108             
if (isRunning)
109             {
110                 
if (isUpdateTask)
111                 {
112                     stateTime -= Time.deltaTime;
113                    
114                     
if (stateTime <= 0)
115                     {
116                         stateTime =
0;
117                         SetVisible(
false);
118                         comboIndex = -
1;
119                         comboType = ComboType.NONE;
120                         numberCombo =
0;
121                         isUpdateTask =
false;
122                     }
123                     task.transform.localScale =
new Vector3(stateTime / totalTime, 1, task.transform.localScale.z);
124                 }
125             }
126         }
127     }
128 }


numberCombo = 0;




Trò chơi đua xe động vật trong UNITY Engine 114.835 lượt xem

Gõ tìm kiếm nhanh...